import { InputQuestion, QuestionBase, SelectQuestion, TimeQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { Api } from '@/config/api/fileAuthority';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'code',
        label: '文件权限编码',
        value: null
      }),
      new InputQuestion({
        key: 'name',
        label: '文件权限名称',
        value: null
      }),
      new TimeQuestion({
        key: 'createdTime',
        label: '创建时间',
        value: [],
        state: {
          showTime: true,
          keySplit: ['createdTimeStart', 'createdTimeEnd'],
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss'
        }
      }),
      new TimeQuestion({
        key: 'modifiedTime',
        label: '修改时间',
        value: [],
        state: {
          showTime: true,
          keySplit: ['modifiedTimeStart', 'modifiedTimeEnd'],
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss'
        }
      })
    ];
    return questions;
  }
  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'code',
        value: '文件权限编码',
        type: 'router',
        state: {
          key: 'code',
          type: 'local'
        }
      }),
      new TextTable({
        key: 'name',
        value: '文件权限名称'
      }),

      new TextTable({
        key: 'remark',
        value: '备注'
      }),
      new TextTable({
        key: 'status',
        value: '状态',
        type: 'slot',
        state: {
          slotName: 'stateSwitch'
        }
      }),
      new TextTable({
        key: 'creatorName',
        value: '创建人'
      }),
      new TextTable({
        key: 'createdTime',
        value: '创建时间'
      }),
      new TextTable({
        key: 'modifierName',
        value: '修改人'
      }),
      new TextTable({
        key: 'modifiedTime',
        value: '修改时间'
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        columns: {
          fixed: 'right',
          width: 120
        },
        handle: [
          {
            type: 'delete',
            url: Api.commonFilePermissionDelete, // 改 query => path
            postType: 'post',
            urlName: 'id',
            text: '删除',
            class: 'text-primary',
            state: {
              key: ''
            }
            // showKey: [{ key: 'status', value: 0 }]
          }
        ]
      })
    ];
    return tables;
  }
  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'local',
        value: '添加',
        type: 'primary',
        class: 'icon-add',
        state: {}
      }),
      new TextTable({
        key: 'delete',
        value: '删除',
        type: 'default',
        class: 'icon-delete',
        state: {
          postType: 'post',
          keyName: 'ids',
          type: 'array',
          url: Api.batchDelete
        }
      })
    ];
    return icons;
  }
}

export default new HomeService();
